<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    Function.prototype.apply = function(ctx, args) {
      ctx = ctx || {}
      ctx._fn = this
      const res = ctx._fn(...args)
      delete ctx._fn
      return res
    }

    Function.prototype.bind = function(ctx, args) {
      ctx = ctx
      return function (...more) {
        this.apply(ctx, args)
      }
    }

    // Function.prototype.apply = function(ctx, args) {
    //     ctx = ctx || window
    //     ctx._fn = this
    //     const res = ctx._fn(...args)
    //     delete ctx._fn
    //     return res
    // }
    // const obj = {0: 1, 1:2, 2: 3, length: 3}
    // const r = Array.prototype.slice.apply(obj, [1])
    // console.log(r)

    // Function.prototype.bind = function(ctx, args) {
    //   ctx = ctx || window
    //   ctx._fn = this
    //   return (...more)=> {
    //     const res = ctx._fn(...args, ...more)
    //     delete ctx._fn
    //     return res
    //   }        
    // }
  </script>
</body>
</html>